<div class="box white_bg">
<?if (!isset($this->viewParams['items'])) :?>
 No <?=$this->viewParams['contentType'] ?> posted yet
<?else:?>
<?
$pageCount = ceil($this->viewParams['paginator']->getTotalItemCount()/$this->viewParams['paginator']->getItemCountPerPage());
?>

<?
	$sess = new Zend_Session_Namespace(CLU_NS);
?>

<?foreach ($this->viewParams['items'] as $i=> $item) :?>

 <?if($item['poster_id'] == $sess->userId) :?>
		  <div class="box" style="border-bottom:1px solid #DFDFDF;">
		  <div class="mouse_action-<?=$item['id']?>">
		     <div class="chitiet_title">&nbsp;&nbsp;
		     	<?  if ($this->viewParams['contentType'] == "place" ||
		     				$this->viewParams['contentType'] == "event"  ) 
		     		{
		     			$link = $this->hvnUrl(array('module' => $this->viewParams['contentType'], 'action' => "view"),"nocontroller") . "?id=" . $item['id'];
		     			$edit = $this->hvnUrl(array('module' => $this->viewParams['contentType'], 'action' => "edit"),"nocontroller") . "?id=" . $item['id'];;
		     		}
		     	    else
		     	    {
		     	    	$link = $this->hvnUrl(array('type' => $this->viewParams['contentType'], 'action' => "view"),"node") . "?id=" . $item['id'];
		     	    	$edit = $this->hvnUrl(array('type' => $this->viewParams['contentType'], 'action' => "edit"),"node") . "?id=" . $item['id'];
		     	    }
			     
		     	    if (isset($this->viewParams["aList"][$item['id']]['article_title']))
		     	    { 
			     		$title = $this->viewParams["aList"][$item['id']]['article_title'];
			     		$body = $this->viewParams["aList"][$item['id']]['article_body'];	
					}
		     	   	else
		     	   	{
		     	   		$title = $item['title'];
		     	   		$body = $item['body'];
		     	   	}
		     	   	$metadata = unserialize($item['metadata']);
		     	   	if ($this->viewParams['contentType'] == "place")
		     	   	{
		     	   		if (isset($metadata['type_name']))
		     	   			$categoryName = $metadata['type_name'];
		     	   	}  
		     	   	else if ($this->viewParams['contentType'] == "gallery")
		     	   	{
		     	   		if (trim($item['category']) == "-2") //event
		     	   		{
		     	   			$categoryLink = $this->hvnUrl(array('module' => 'event', "action" => "view"), "nocontroller") . "?id=" . $metadata['content_id'];
		     	   			$categoryName = "<a href='" . $categoryLink . "'> " . $metadata['content_title'] . "</a>";
		     	   		}
		     	   		else if ($item['category'] == '-1') //place
		     	   		{
		     	   			$categoryLink = $this->hvnUrl(array('module' => 'place', "action" => "view"), "nocontroller") . "?id=" . $metadata['content_id'];
		     	   			$categoryName = "<a href='" . $categoryLink . "'> " . $metadata['content_title'] . "</a>";

		     	   		}
		     	   		else
		     	   			$categoryName = $this->viewParams['contentType'] ;
		     	   	}
		     	   	else
		     	   	{
		     	   		if (isset($metadata['category_name']))
		     	   			$categoryName = $metadata['category_name'];
		     	   	}
		     	   	if (!isset($categoryName))
		     	   		$categoryName = "No category";
		     	?>
		     	
			     <a href="<?= $link?>">
			     <?= ($this->viewParams['paginator']->getCurrentPageNumber() - 1) * $this->viewParams['paginator']->getItemCountPerPage() + $i + 1?>. <?=$title ?>
			     </a>
			 </div>
			<div class="blog_news" align="left">
				<div class="blog_news_left">
					<?=t(1020)?>  
					<? if (isset($item['created'])) :?>
					<?=date("j/n/Y", $item['created'])?>
					<?else :?>
					<?=date("j/n/Y", $this->viewParams["aList"][$item['id']]['article_post_time'])?>
					<?endif ?>,
					<?=t(827)?> <?=p($categoryName)?> 
				</div>
				<div class="blog_news_right"><?=$item['views'] + 100 ?> <?=t(1019)?> - <?=$item['comments']?> 
					<?=t(601)?><?if($sess->viewLang == 'en' && $item['comments'] > 0) echo 's'?>
				</div>
				<div class="clear"></div>
			</div>
			<div class="clear"></div>
			<div class="news_img">
			<? if (isset($item['thumb'])) :?>
			<img src="<?=str_replace("/original/", "/xsmall/", $item['thumb'])?>" align="absmiddle" />
			<?else :?>
			<img src="/public/themes/prime/images/common/75x75_no_image.gif" align="absmiddle" />
			<?endif?> 
			</div>

			 <div class="text">
			     <?= substring_n_words(strip_tags($body), 100) ;?> ...
			 </div>
			 
			 <div class="detail">
			 	<a  style="color:#324171;" href="<?=$link?>"><?=t(150)?>...</a>
			 </div>

			 <div style="height:30px;width:400px; padding: 2px 0 0;">
		        <div align = "right" class = "tr-action" style="display:none">
		        <?if ((isset($sess->userId) && (strpos($sess->userPermissions, 'update ' . $this->viewParams['contentType']) ||
                   ($sess->userId == $item['poster_id'] && strpos ($sess->userPermissions, 'update own ' . $this->viewParams['contentType'])
                        )))):
             	?>
		        	<a href="<?=$edit?>"><?=t(38)?> </a>|
		        <?endif?>
		        <?if ((isset($sess->userId) && (strpos($sess->userPermissions, 'delete ' . $this->viewParams['contentType']) ||
                   ($sess->userId == $item['poster_id'] && strpos ($sess->userPermissions, 'delete own ' . $this->viewParams['contentType'])
                        )))):
             	?>
			    	<a href="javascript:void()" name="item-delete-<?=$this->viewParams['contentType']?>-<?=$item['id']?>"><?=t(31)?></a>
			     <?endif?>
		        </div>
		    </div>
		  </div>
		  </div>
		<script type="text/javascript">
			var oriLang = '<?= get_language_from_int($item['language'])?>';
			var lang = '<?= $sess->viewLang?>';
			googleTranslate(oriLang, lang, 'chitiet_title', 'text');
		</script>
<div>
<? if ($pageCount > 1) :?>
	<?= $this->paginationControl($this->viewParams['paginator'], 'Sliding', '/modules/common/views/scripts/commonTheme/commonLang/common/clu-pagination-control.phtml',
							    array('searchUrl' => $this->viewParams['searchUrl'])); ?>
<?endif ?>
</div>
	<?endif?>
<?endforeach ?>
<?endif ?>

</div>
<style type="text/css">
.gray-bg
{
	background-color : #c8cbd6;
}
</style>
<script type="text/javascript">

$(function() {
    $("[class^=mouse_action]").mouseover(function(e){
                        $(this).find(".tr-action").show();
                        $(this).find(".blog_news").addClass("gray-bg");
                }).mouseout(function(){
                        $(this).find(".tr-action").hide();
                        $(this).find(".blog_news").removeClass("gray-bg");
                });
    
	$("[name^=item-delete-]").click(function(e){
		var del=confirm("Do you want to delete this item?");
		deleteId = this.name.split('-')[3];
		type = this.name.split('-')[2];
		messeage = '';
		
		if (del){	
			if(type == 'place')
			{
				$.getJSON("/<?=$sess->viewLang?>/place/ajax/delete-place", {'id': deleteId},function(json) {
					if(json.success)	
						$(".mouse_action-"  + deleteId).css('background-color','red').fadeOut(2000);
	               	else
	               		$(".mouse_action-"  + deleteId).show().html("<?=t(729)?>");
	               return false;
				});
			}
			else if(type == 'event')
			{
				$.getJSON("/<?=$sess->viewLang?>/event/ajax/delete-event", {'id': deleteId},function(json) {
					if(json.success)	
						$(".mouse_action-"  + deleteId).css('background-color','red').fadeOut(2000);
	               	else
	               		$(".mouse_action-"  + deleteId).show().html("<?=t(729)?>");
	               return false;
				});
			}
			else
			{
				$.getJSON("/<?=$sess->viewLang?>/node/ajax/delete-node", {'id': deleteId,'type':type},function(json) {
					console.log(json);
					if(json.success)	
						$(".mouse_action-"  + deleteId).css('background-color','red').fadeOut(2000);
	               	else
	               		$(".mouse_action-"  + deleteId).show().html("<?=t(729)?>");
	               return false;
				});
			}
		}else
			return false;
	});
});
</script>
	
